<template>
	<view class="wrap back">
		<view class="wrap_box" style="height: calc(100%)">
			<view class="header">
				电子签单-test
			</view>
			<!-- 待办事项 -->

			<card title="待办事项">
				<template #resetBut>
					<view class="" style="display: flex;" @click="goToPath('/pages/homePage/ready')">
						<span>全部待办</span><u-icon name="arrow-right"></u-icon>
					</view>
				</template>
				<template #main>
					<bill-item v-for="(item,index) in billList" :key="item.id" :form="item" @goSignDetail="goSignDetail"
						:infoAirline="item.billInfo['info-airline']" />
				</template>
			</card>

			<card title="服务项目" style="margin-top:10px;">
				<template #main>
					<view class="tagList">
						<view class="tagCard" v-for="(item,index) in tagIcon" :key="index" @click="goFlight(item)"
							:style="{'background':item.color}">
							<view class="font">
								{{item.name}}
							</view>
							<img class="img" :src="'static/images/home/' + item.icon + '.png'">
						</view>
					</view>
				</template>
			</card>
		</view>
	</view>
</template>

<script>
	import {
		httpAction
	} from '@/api/manage';
	import {
		mapActions
	} from "vuex";
	export default {
		data() {
			return {
				billList: [],
				iconPath: 'static/images/home/heart.png',
				tagIcon: {
					// 前端演示数据， 目前以中文标题 判定 icon，颜色只有三组，左中右各不同的颜色
					// icon是带颜色的， 颜色也得加上
					'一般勤务': {
						name: '一般勤务',
						icon: 'heart',
						color: '#08a2fc'
					},
					'特车服务': {
						name: '特车服务',
						icon: 'car',
						color: '#5479fe'
					},
					'飞机服务': {
						name: '飞机服务',
						icon: 'air',
						color: '#bb75e6'
					},
					'非例行服务': {
						name: '非例行服务',
						icon: 'heart',
						color: '#08a2fc'
					},
					'除/防冰服务': {
						name: '除/防冰服务',
						icon: 'service',
						color: '#5479fe'
					},
					'客桥': {
						name: '客桥',
						icon: 'birdge',
						color: '#bb75e6'
					},
				},
				tags: []
			}
		},
		onLoad: function() {
			this.getData()
			this.getChargeAssuranceList()
		},
		onShow: function() {
			this.getData()
		},
		methods: {
			...mapActions(["getChargeAssuranceList", ]),
			getData() {
				// 获取待办事项
				httpAction('/system/receipt/list', {
					signStatus: 1
				}, 'get').then(res => {
					if (res.data && res.data.records) {
						if (res.data.records.length > 3) {
							res.data.records = res.data.records.slice(0, 3)
						}
						res.data.records.forEach(item => {
							item.billInfo = JSON.parse(item.billInfo)
						})
						this.billList = res.data.records
					} else {
						// toast('服务数据请求失败，请刷新重试')
					}
				})
				// 获取特殊服务
				// httpAction('/system/item/list', {}, 'get').then(res => {
				// 	const _this = this
				// 	if (res.data && res.data.records) {
				// 		res.data.records.forEach(r => {
				// 			if(_this.tagIcon[r.chargeName]){
				// 				r.icon = 'static/images/home/' + _this.tagIcon[r.chargeName].icon + '.png'
				// 				r.color = _this.tagIcon[r.chargeName].color
				// 			}else {
				// 				r.icon = 'static/images/home/heart.png'
				// 				r.color = '#08a2fc'
				// 			}
				// 		})
				// 		this.tags = res.data.records
				// 	} else {
				// 		// toast('服务数据请求失败，请刷新重试')
				// 	}
				// })
			},
			// 前往签单详情
			goSignDetail(item) {
				this.$store.commit("GETBILLINFO", item);
				console.log(item)
				this.$tab.navigateTo('/pages/signBill/billDetail')
			},
			goFlight(item) {
				this.$tab.navigateTo('/pages/flight/serviceList')
			},
			goToPath(path) {
				this.$tab.navigateTo(path)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.back {
		background: url(~@/static/images/home/home.png) 0px -1px no-repeat !important;
		background-size: 100% !important;
	}

	.header {
		height: 15%;
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #fff;
		font: normal 400 20px "SourceHanSansCN-Medium";
	}

	.tagList {
		display: flex;
		flex-wrap: wrap;

		// 按照3的倍数计算样式
		.tagCard:nth-of-type(3n+1) {
			background: #08a2fc;
		}

		.tagCard:nth-of-type(3n+2) {
			background: #5479fe;
		}

		.tagCard:nth-of-type(3n+3) {
			background: #bb75e6;
		}

		.tagCard {
			width: 30%;
			height: 74px;
			margin-right: 3%;
			margin-bottom: 10px;
			background: #08a2fc;
			color: #fff;
			cursor: pointer;
			padding: 10px;
			border-radius: 10px;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.font {
				font: normal 700 14px 'SourceHanSansCN-Medium';
				height: 24px;
			}

			.img {
				// width: 50%;
				// height: 60%;
				// display: flex;
				align-self: flex-end;
				position: relative;
				width: 40px;
				height: 30px;
				// margin-top: 20px;
				// margin-right: 5%;
			}
		}
	}
</style>